package utilities;

import java.io.*;
import java.lang.*;

public class IOHelp {
	
	
	/**
	 * @return
	 * @throws Exception
	 */
	public static String getLineAsString() throws Exception {
		BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
		return reader.readLine();
	}
	
	/**
	 * @return
	 * @throws Exception
	 */
	public static int getLineAsInt() throws Exception {
		BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
		return Integer.parseInt(reader.readLine());
	}
	
	/**
	 * @return
	 * @throws Exception
	 */
	public static double getLineAsDouble() throws Exception {
		BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
		return Double.parseDouble(reader.readLine());
	}
	
	/**
	 * Stellt
	 * @param file File
	 * @param charset String
	 * @return BufferedReader
	 * @throws IOException
	 * @throws FileNotFoundException
	 * @since JDK 1.6
	 * 
	 */
	public static BufferedReader getBufferedFileReader(File file, String charset) throws IOException, FileNotFoundException {
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis, charset);
		BufferedReader br = new BufferedReader(isr);	
		
		return br;
	}
	
	/**
	 * @param file String
	 * @param charset String
	 * @return BufferedReader
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	public static BufferedReader getBufferedFileReader(String file, String charset) throws IOException, FileNotFoundException {
		File file_object = new File(file);
		return IOHelp.getBufferedFileReader(file_object, charset);
	}
	
	/**
	 * @param file
	 * @param expand
	 * @return
	 * @throws FileNotFoundException
	 * @throws UnsupportedEncodingException
	 */
	public static PrintWriter getBufferedPrintWriter(String file,
			Boolean expand)
					throws FileNotFoundException, UnsupportedEncodingException {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file));
		return new PrintWriter(new BufferedWriter(osw), expand);
	}
	
	public static PrintWriter getBufferedPrintWriter(File file,
			Boolean expand)
					throws FileNotFoundException, UnsupportedEncodingException {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file));
		return new PrintWriter(new BufferedWriter(osw), expand);
	}

	/**
	 * @param file
	 * @param expand
	 * @param charset
	 * @return
	 * @throws FileNotFoundException
	 * @throws UnsupportedEncodingException
	 */
	public static PrintWriter getBufferedPrintWriter(String file, 
			Boolean expand,
			String charset)
					throws FileNotFoundException, UnsupportedEncodingException {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file), charset);
		return new PrintWriter(new BufferedWriter(osw), expand);
	}
	
	public static PrintWriter getBufferedPrintWriter(File file, 
			Boolean expand,
			String charset)
					throws FileNotFoundException, UnsupportedEncodingException {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file), charset);
		return new PrintWriter(new BufferedWriter(osw), expand);
	}
	
}
